#include "stdafx.h"
#include "RobotModel.h"


RobotModel::RobotModel(void)
{

}


RobotModel::~RobotModel(void)
{
	clear();
}

void RobotModel::clear()
{
	for (RobotInfoMap::iterator it_Map = _robotInfoMap.begin(); it_Map != _robotInfoMap.end(); ++it_Map)
	{
		RobotInfo *p = it_Map->second;
		delete p;
	}
	_robotInfoMap.clear();
}

RobotInfo* RobotModel::getRobotInfoByKey( const std::string &key )
{
	RobotInfo *pRet = NULL;
	RobotInfoMap::iterator it_Map = _robotInfoMap.find(key);
	if (it_Map != _robotInfoMap.end())
	{
		pRet = it_Map->second;
	}
	return pRet;
}

void RobotModel::addRobotInfo( const std::string &key, const RobotInfo &robotInfo)
{
	RobotInfo* pRobot = NULL;
	RobotInfoMap::iterator it_Map = _robotInfoMap.find(key);
	if (it_Map != _robotInfoMap.end())
		pRobot = it_Map->second;
	else
		pRobot = new RobotInfo();
	if (pRobot)
	{
		pRobot->strMac   = robotInfo.strMac;
		pRobot->strIp    = robotInfo.strIp;
		pRobot->strState = robotInfo.strState;
		pRobot->strTime  = robotInfo.strTime;
		_robotInfoMap.insert(make_pair(key, pRobot));
	}
}
